package com.rainng.coursesystem.controller.leader;

import com.rainng.coursesystem.config.themis.annotation.Admin;
import com.rainng.coursesystem.config.themis.annotation.Leader;
import com.rainng.coursesystem.controller.BaseController;
import com.rainng.coursesystem.model.entity.TeamEntity;
import com.rainng.coursesystem.model.vo.response.ResultVO;
import com.rainng.coursesystem.service.admin.TeamService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Leader(Leader.TEAM_MANAGE)
@RequestMapping("/leader/team")
@RestController
public class TeamController1 extends BaseController {
    private final TeamService service;

    public TeamController1(TeamService service) {
        this.service = service;
    }

    @GetMapping("/{id}")
    public ResultVO get(@PathVariable Integer id) {
        return service.get(id);
    }

    @PostMapping
    public ResultVO create(@RequestBody @Validated TeamEntity entity) {
        return service.create(entity);
    }

    @DeleteMapping("/{id}")
    public ResultVO delete(@PathVariable Integer id) {
        return service.delete(id);
    }

    @PutMapping
    public ResultVO update(@RequestBody @Validated TeamEntity entity) {
        return service.update(entity);
    }

    @RequestMapping("/page/count")
    public ResultVO getPageCount(String areaName, String activityName, String name) {
        return service.getPageCount(areaName, activityName, name);
    }

    @RequestMapping("/page")
    public ResultVO getPage(String areaName, String activityName, String name) {
        return service.getPage(1, areaName, activityName, name);
    }

    @RequestMapping("/page/{index}")
    public ResultVO getPage(@PathVariable Integer index, String areaName, String activityName, String name) {
        return service.getPage(index, areaName, activityName, name);
    }

    @Leader
    @RequestMapping("/names")
    public ResultVO listName() {
        return service.listName();
    }
}
